package com.lzjt.controller;

import com.lzjt.param.MedicalPolicyParam;
import com.lzjt.service.MedicalPolicyService;
import com.lzjt.util.Msg;// 修改导入的 StringUtils 类
import org.springframework.util.StringUtils;

import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.security.RolesAllowed;

@Api(tags="医保政策控制器类")
@RestController
@RequestMapping("/api/medical_Policys")
@CrossOrigin

public class MedicalPolicyController {
    @Autowired
    private MedicalPolicyService medicalPolicyService;
    @RolesAllowed({"1"})
    @PostMapping(value="")
    public Msg saveMedicalPolicy(@RequestBody MedicalPolicyParam param){
        Msg msg=medicalPolicyService.saveMedicalPolicy(param);
        return msg;
    }
    @RolesAllowed({"1"})
    @PutMapping(value="/{id}")
    public Msg updateMedicalPolicy(@PathVariable("id") Long id, @RequestBody MedicalPolicyParam param){
        if(!StringUtils.hasLength(param.getTitle())){
            return Msg.fail().mess("标题不能为空");
        }
        if(!StringUtils.hasLength(param.getMessage())){
            return Msg.fail().mess("内容不能为空");
        }
        if(param.getCityId() == null){
            return Msg.fail().mess("城市不能为空");
        }
        return medicalPolicyService.updateMedicalPolicy(id, param);
    }

    @GetMapping(value="")
    public Msg getMedicalPolicyWithPage(MedicalPolicyParam param)
    {
        Msg msg = medicalPolicyService.getMedicalPolicyWithPage(param);
        return msg;
    }
   @RolesAllowed({"1"})
    @DeleteMapping("/{id}")
    public Msg deleteMedicalPolicy(@PathVariable("id") Long id){
        Msg msg = medicalPolicyService.deleteMedicalPolicy(id);
        return msg;
    }

}
